//$Id$

using System;
using System.Collections.Generic;
using System.Text;
using Salamanca;
using Salamanca.DataAccess;
using Salamanca.DataAccess.Collections;
using Salamanca.DataActivities;
using Salamanca.DataActivities.UI;
using Salamanca.DataRules;

namespace Northwind.DomainModel.Activities
{



    partial interface IOrderDetailsCrudQuestionFactory
    {

        /// <summary>Gets a question about a <see cref="DomainModel.OrderDetails" /> instance.</summary>
        Question AskOrderDetailsInfos(ActivityController controller, DomainModel.OrderDetails domainModel);
    }



    partial class OrderDetailsCreate<TActivityData>
    {

        /// <summary>Performs the actual initialization of a new <see cref="DomainModel.OrderDetails" /> instance.</summary>
        private ActivityStateResult _Handle(IActivityController controller)
        {
            Data.OrderDetails=new DomainModel.OrderDetails(((IDataActivityParameters)Parameters).DataMappers);
            return ActivityStateResult.Next;
        }

        /// <summary>Gets the next state.</summary>
        private ActivityState<TActivityData> _NextState
        {
            get
            {
                if (_NextStateCreator!=null)
                    return _NextStateCreator(Data, Parameters);

                return new EndActivityState<TActivityData>(Data);
            }
        }

        private NextStateCreateHandler<TActivityData> _NextStateCreator;
    }



    partial class OrderDetailsAskInfos<TActivityData, TQuestionFactory>
    {

        /// <summary>Raises the <see cref="ActivityState{TActivityData}.Initialized" /> event.</summary>
        private void _OnInitialized(ActivityStateEventArgs e)
        {
            Question=((IQuestionFactoryParameters<TQuestionFactory>)Parameters).QuestionFactory.AskOrderDetailsInfos((ActivityController)e.Controller, Data.OrderDetails);
            base.OnInitialized(e);
        }

        /// <summary>Gets the next state.</summary>
        private ActivityState<TActivityData> _NextState
        {
            get
            {
                if (_NextStateCreator!=null)
                    return _NextStateCreator(Data, Parameters);

                return new EndActivityState<TActivityData>(Data);
            }
        }

        private NextStateCreateHandler<TActivityData> _NextStateCreator;
    }



    partial class OrderDetailsSave<TActivityData>
    {

        /// <summary>Performs the actual saving of the <see cref="DomainModel.OrderDetails" /> instance.</summary>
        private ActivityStateResult _Handle(IActivityController controller)
        {
            Data.OrderDetails.Save();
            return ActivityStateResult.Next;
        }

        /// <summary>Gets the next state.</summary>
        private ActivityState<TActivityData> _NextState
        {
            get
            {
                if (_NextStateCreator!=null)
                    return _NextStateCreator(Data, Parameters);

                return new EndActivityState<TActivityData>(Data);
            }
        }

        private NextStateCreateHandler<TActivityData> _NextStateCreator;
    }



    partial class OrderDetailsDelete<TActivityData>
    {

        /// <summary>Performs the actual deletion of the <see cref="DomainModel.OrderDetails" /> instance.</summary>
        private ActivityStateResult _Handle(IActivityController controller)
        {
            Data.OrderDetails.Delete();
            return ActivityStateResult.Next;
        }

        /// <summary>Gets the next state.</summary>
        private ActivityState<TActivityData> _NextState
        {
            get
            {
                if (_NextStateCreator!=null)
                    return _NextStateCreator(Data, Parameters);

                return new EndActivityState<TActivityData>(Data);
            }
        }

        private NextStateCreateHandler<TActivityData> _NextStateCreator;
    }

}
